package jp.co.cos.ittrick.channel.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

@Model(schemaVersion = 1)
public class ApplicationModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    /**
     * アプリケーションID
     */
    private String applicationId;

    /**
     * アプリ名
     */
    private String applicationName;

    /** Meta Description */
    private String description;

    /** キーワードリスト */
    private List<String> keyWordList;

    /** アプリの説明 */
    private Text applContent;

    /** twitter アカウント */
    private String twitterAccount;

    /** 更新日時 */
    private Date lastmod;

    /** アプリケーションロゴイメージコード */
    private String applLogoImageCode;

    /** アプリケーションバックグランドイメージコード */
    private String applBackgroundImageCode;

  //--------------------永久化しない項目---------------------------------

    public String getContentString() {
        if(applContent != null && applContent.getClass() != null) {
            return applContent.getValue();
        }else {
            return "";
        }
    }

    public String getLastmodOfFormat() {
        SimpleDateFormat fm1 = new SimpleDateFormat("yyyy-MM-dd");
        return fm1.format(lastmod);
    }

    public String getKeyWordListString() {

        String keyWordString = "";
        for(int i = 0; i < keyWordList.size(); i++) {
            if(i == 0) {
                keyWordString = keyWordList.get(i);
            }else {
                keyWordString = keyWordString + "," + keyWordList.get(i);
            }
        }
        return keyWordString;
    }

//----------------------メソッド---------------------------------------

    /**
     * Returns the key.
     *
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * Sets the key.
     *
     * @param key
     *            the key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * Returns the version.
     *
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * Sets the version.
     *
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((key == null) ? 0 : key.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        ApplicationModel other = (ApplicationModel) obj;
        if (key == null) {
            if (other.key != null) {
                return false;
            }
        } else if (!key.equals(other.key)) {
            return false;
        }
        return true;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setTwitterAccount(String twitterAccount) {
        this.twitterAccount = twitterAccount;
    }

    public String getTwitterAccount() {
        return twitterAccount;
    }

    public void setApplContent(Text applContent) {
        this.applContent = applContent;
    }

    public Text getApplContent() {
        return applContent;
    }

    public void setApplicationId(String applicationId) {
        this.applicationId = applicationId;
    }

    public String getApplicationId() {
        return applicationId;
    }

    public void setLastmod(Date lastmod) {
        this.lastmod = lastmod;
    }

    public Date getLastmod() {
        return lastmod;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setApplLogoImageCode(String applLogoImageCode) {
        this.applLogoImageCode = applLogoImageCode;
    }

    public String getApplLogoImageCode() {
        return applLogoImageCode;
    }

    public void setApplBackgroundImageCode(String applBackgroundImageCode) {
        this.applBackgroundImageCode = applBackgroundImageCode;
    }

    public String getApplBackgroundImageCode() {
        return applBackgroundImageCode;
    }

    public void setKeyWordList(List<String> keyWordList) {
        this.keyWordList = keyWordList;
    }

    public List<String> getKeyWordList() {
        return keyWordList;
    }
}
